/**
 * \license
 * Copyright Lassi Marttala 2013
 * 
 * This file is part of dlt2jpa.
 *
 * dlt2jpa is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dlt2jpa is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with dlt2jpa.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.fizzl.dlt.message;

import java.lang.reflect.Array;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

@Entity
public class DltPayloadArgument {
	@Id
	private long id;
	
	private int				typeLength;
	private byte[]			data;
	private boolean			variableInfo;
	private ArgumentType	type;
	private Object 			value;
	
	@Transient 
	private int length;
	public int getLength() {
		return length;
	}
	public void setLength(int length) {
		this.length = length;
	}
	
	public Class<?> getValueType() {
		switch(getType()) {
		case TypeArray:
			return Array.class;
		case TypeBool:
			return Boolean.class;
		case TypeFixedPoint:
			return String.class;
		case TypeFloat:
			return Float.class;
		case TypeInt:
			return Integer.class;
		case TypeRaw:
			return byte[].class;
		case TypeString:
			return String.class;
		case TypeUInt:
			return Long.class;
		default:
			return Object.class;
		}
	}
	// Inner enum for types
	public enum ArgumentType {
		TypeBool,
		TypeInt,
		TypeUInt,
		TypeFloat,
		TypeArray,
		TypeString,
		TypeRaw,
		TypeFixedPoint
	}

	// Getters and setters
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public int getTypeLength() {
		return typeLength;
	}
	public void setTypeLength(int typeLength) {
		this.typeLength = typeLength;
	}
	public byte[] getData() {
		return data;
	}
	public void setData(byte[] data) {
		this.data = data;
	}
	public boolean isVariableInfo() {
		return variableInfo;
	}
	public void setVariableInfo(boolean variableInfo) {
		this.variableInfo = variableInfo;
	}
	public ArgumentType getType() {
		return type;
	}
	public void setType(ArgumentType type) {
		this.type = type;
	}
	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	};
}
